package testConstructor;

import testClass.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test1 {
    public static void main(String[] args) {
        //构造函数对象Constructor无法被实例化
        Class<Student> st = Student.class;
        //获取Student类中的构造函数个数
        Constructor<?>[] declaredConstructors = st.getDeclaredConstructors();
        System.out.println("数组长度："+declaredConstructors.length);

        for (Constructor<?> d : declaredConstructors) {
            System.out.println("构造函数名"+d.getName());
            int modifiers = d.getModifiers();
            String s = Modifier.toString(modifiers);
            System.out.println("访问修饰符"+s);
            int parameterCount = d.getParameterCount();
            System.out.println("参数个数"+parameterCount);
            Class<?>[] parameterTypes = d.getParameterTypes();
            String collect = Stream.of(parameterTypes)
                    .map(t -> t.getName())
                    .collect(Collectors.joining(","));
            System.out.println("参数类型"+collect);
            System.out.println();

        }
    }
}
